/*
 * @Author: kenan
 * @Date: 2022-01-17 16:38:21
 * @LastEditors: kenan
 * @LastEditTime: 2022-11-01 13:40:02
 * @Description: file content
 */
package system

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/system"
	"github.com/pkg/errors"
	"gorm.io/gorm"
)

var BaseMenu = new(menu)

type menu struct{}

func (m *menu) TableName() string {
	return "sys_base_menus"
}

func (m *menu) Initialize() error {
	entities := []system.SysBaseMenu{
		// {MenuLevel: 0, Hidden: false, ParentId: "0", Path: "https://smartide.cn/", Name: "https://smartide.cn", Component: "/", Sort: 0, Meta: system.Meta{Title: "官方网站", Icon: "home-filled"}},
		{MenuLevel: 0, Hidden: false, ParentId: "0", Path: "dashboard", Name: "dashboard", Component: "view/dashboard/index.vue", Sort: 10, Meta: system.Meta{Title: "仪表盘", Icon: "odometer"}},
		{MenuLevel: 0, Hidden: false, ParentId: "0", Path: "admin", Name: "superAdmin", Component: "view/superAdmin/index.vue", Sort: 30, Meta: system.Meta{Title: "管理员", Icon: "user"}},
		{MenuLevel: 0, Hidden: false, ParentId: "2", Path: "authority", Name: "authority", Component: "view/superAdmin/authority/authority.vue", Sort: 1, Meta: system.Meta{Title: "角色管理", Icon: "avatar"}},
		{MenuLevel: 0, Hidden: true, ParentId: "2", Path: "dictionaryDetail/:id", Name: "dictionaryDetail", Component: "view/superAdmin/dictionary/sysDictionaryDetail.vue", Sort: 1, Meta: system.Meta{Title: "字典详情", Icon: "order"}},
		{MenuLevel: 0, Hidden: false, ParentId: "2", Path: "menu", Name: "menu", Component: "view/superAdmin/menu/menu.vue", Sort: 2, Meta: system.Meta{Title: "菜单管理", Icon: "tickets", KeepAlive: true}},
		{MenuLevel: 0, Hidden: false, ParentId: "2", Path: "api", Name: "api", Component: "view/superAdmin/api/api.vue", Sort: 3, Meta: system.Meta{Title: "api管理", Icon: "platform", KeepAlive: true}},
		{MenuLevel: 0, Hidden: false, ParentId: "2", Path: "user", Name: "user", Component: "view/superAdmin/user/user.vue", Sort: 4, Meta: system.Meta{Title: "用户管理", Icon: "coordinate"}},
		{MenuLevel: 0, Hidden: false, ParentId: "2", Path: "dictionary", Name: "dictionary", Component: "view/superAdmin/dictionary/sysDictionary.vue", Sort: 5, Meta: system.Meta{Title: "字典管理", Icon: "notebook"}},
		{MenuLevel: 0, Hidden: false, ParentId: "2", Path: "operation", Name: "operation", Component: "view/superAdmin/operation/sysOperationRecord.vue", Sort: 6, Meta: system.Meta{Title: "操作历史", Icon: "pie-chart"}},
		{MenuLevel: 0, Hidden: true, ParentId: "0", Path: "person", Name: "person", Component: "view/person/person.vue", Sort: 40, Meta: system.Meta{Title: "个人信息", Icon: "message"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "0", Path: "systemTools", Name: "systemTools", Component: "view/systemTools/index.vue", Sort: 50, Meta: system.Meta{Title: "系统工具", Icon: "tools"}},
		// {MenuLevel: 0, Hidden: true, ParentId: "12", Path: "autoCodeEdit/:id", Name: "autoCodeEdit", Component: "view/systemTools/autoCode/index.vue", Sort: 0, Meta: system.Meta{Title: "自动化代码（复用）", Icon: "magic-stick"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "12", Path: "autoCodeAdmin", Name: "autoCodeAdmin", Component: "view/systemTools/autoCodeAdmin/index.vue", Sort: 1, Meta: system.Meta{Title: "自动化代码管理", Icon: "magic-stick"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "12", Path: "autoCode", Name: "autoCode", Component: "view/systemTools/autoCode/index.vue", Sort: 1, Meta: system.Meta{Title: "代码生成器", Icon: "cpu", KeepAlive: true}},
		// {MenuLevel: 0, Hidden: false, ParentId: "12", Path: "formCreate", Name: "formCreate", Component: "view/systemTools/formCreate/index.vue", Sort: 2, Meta: system.Meta{Title: "表单生成器", Icon: "magic-stick", KeepAlive: true}},
		// {MenuLevel: 0, Hidden: false, ParentId: "12", Path: "system", Name: "system", Component: "view/systemTools/system/system.vue", Sort: 3, Meta: system.Meta{Title: "系统配置", Icon: "operation"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "0", Path: "state", Name: "state", Component: "view/system/state.vue", Sort: 60, Meta: system.Meta{Title: "服务器状态", Icon: "cloudy"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "0", Path: "example", Name: "example", Component: "view/example/index.vue", Sort: 70, Meta: system.Meta{Title: "示例文件", Icon: "management"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "19", Path: "excel", Name: "excel", Component: "view/example/excel/excel.vue", Sort: 4, Meta: system.Meta{Title: "excel导入导出", Icon: "takeaway-box"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "19", Path: "upload", Name: "upload", Component: "view/example/upload/upload.vue", Sort: 5, Meta: system.Meta{Title: "媒体库（上传下载）", Icon: "upload"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "19", Path: "simpleUploader", Name: "simpleUploader", Component: "view/example/simpleUploader/simpleUploader", Sort: 6, Meta: system.Meta{Title: "断点续传（插件版）", Icon: "upload"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "19", Path: "breakpoint", Name: "breakpoint", Component: "view/example/breakpoint/breakpoint.vue", Sort: 6, Meta: system.Meta{Title: "断点续传", Icon: "upload-filled"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "19", Path: "customer", Name: "customer", Component: "view/example/customer/customer.vue", Sort: 7, Meta: system.Meta{Title: "客户列表（资源示例）", Icon: "avatar"}},
		// {MenuLevel: 0, Hidden: false, ParentId: "0", Path: "about", Name: "about", Component: "view/about/index.vue", Sort: 80, Meta: system.Meta{Title: "关于我们", Icon: "info-filled"}},

		//SmartIDE Plugin start
		// 11
		{MenuLevel: 0, Hidden: false, ParentId: "0", Path: "smartide_resource", Name: "smartide_resource", Component: "view/smartide/resource/index.vue", Sort: 20, Meta: system.Meta{Title: "资源管理", Icon: "monitor"}},
		// 12
		{MenuLevel: 0, Hidden: false, ParentId: "0", Path: "smartide", Name: "smartide", Component: "view/smartide/index.vue", Sort: 21, Meta: system.Meta{Title: "工作区", Icon: "partly-cloudy"}},
		//13
		{MenuLevel: 0, Hidden: false, ParentId: "12", Path: "workspace", Name: "workspace", Component: "view/smartide/workspace/index.vue", Sort: 1, Meta: system.Meta{Title: "工作区管理", Icon: "mostly-cloudy"}},
		//14
		{MenuLevel: 0, Hidden: true, ParentId: "12", Path: "workspace/details/:id", Name: "details", Component: "view/smartide/workspace/details.vue", Sort: 2, Meta: system.Meta{Title: "工作区详情", Icon: "mostly-cloudy"}},
		//15
		{MenuLevel: 0, Hidden: false, ParentId: "12", Path: "wspolicy", Name: "wspolicy", Component: "view/smartide/wspolicy/index.vue", Sort: 3, Meta: system.Meta{Title: "工作区策略", Icon: "sunset"}},
		// 16
		{MenuLevel: 0, Hidden: false, ParentId: "0", Path: "smartide_template", Name: "smartide_template", Component: "view/smartide/template/index.vue", Sort: 22, Meta: system.Meta{Title: "模版库", Icon: "postcard"}},
		//17
		{MenuLevel: 0, Hidden: false, ParentId: "0", Path: "smartide_team", Name: "team", Component: "view/smartide/team/index.vue", Sort: 23, Meta: system.Meta{Title: "团队管理", Icon: "coffee"}},

		//18
		{MenuLevel: 0, Hidden: true, ParentId: "12", Path: "workspace/create", Name: "create", Component: "view/smartide/workspace/create.vue", Sort: 2, Meta: system.Meta{Title: "工作区创建", Icon: "mostly-cloudy"}},
		//SmartIDE Plugin end
		//28 smartide workspacepolicy
		// {MenuLevel: 0, Hidden: false, ParentId: "0", Path: "smartide_workspacepolicy", Name: "smartide_workspacepolicy", Component: "view/smartideworkspacepolicy/workspacepolicy/index.vue", Sort: 23, Meta: system.Meta{Title: "工作区管理", Icon: "partly-cloudy"}},
	}
	if err := global.GVA_DB.Create(&entities).Error; err != nil { // 创建 model.User 初始化数据
		return errors.Wrap(err, m.TableName()+"表数据初始化失败!")
	}
	return nil
}

func (m *menu) CheckDataExist() bool {
	if errors.Is(global.GVA_DB.Where("path = ?", "smartide_team").First(&system.SysBaseMenu{}).Error, gorm.ErrRecordNotFound) { // 判断是否存在数据
		return false
	}
	return true
}
